/*************************************************************************************
*Copyright (c) 2011, Intel Mobile Communications GmbH. 
*All rights reserved.
*
*Redistribution and use in source and binary forms, with or without
*modification, are permitted provided that the following conditions are met:
*    * Redistributions of source code must retain the above copyright
*      notice, this list of conditions and the following disclaimer.
*    * Redistributions in binary form must reproduce the above copyright
*      notice, this list of conditions and the following disclaimer in the
*      documentation and/or other materials provided with the distribution.
*    * Neither the name of the <organization> nor the
*      names of its contributors may be used to endorse or promote products
*      derived from this software without specific prior written permission.
*
*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
*ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
*WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
*DISCLAIMED. IN NO EVENT SHALL INTEL MOBILE COMMUNICATIONS GMBH. BE LIABLE FOR ANY
*DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
*(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
*ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
*SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*************************************************************************************/



#include "cef_system_properties.h"
using namespace std;
cef_clock::cef_clock()
{
	name="default";
	id=0;
	frequency=0;
	skew=0;
	derived_from_id=0;
	derivation_type=SYNC;
	derived=false;

}
cef_clock::cef_clock(std::string n,unsigned i,vector<double>* f,unsigned s,unsigned d,cef_derivation_type t, int drf, bool isd)
{
	name=n;
	id=i;
	frequency=f;
	skew=s;
	derived_from_id=d;
	derivation_type=t;
	derived=isd;
	derivation_phase=drf;
}
cef_clock::~cef_clock()
{
	delete frequency;
}
//Setters
void cef_clock::setName(std::string n)
{
	name=n;	
}
void cef_clock::setID(unsigned i)
{
	id=i;
}
void cef_clock::setFrequency(vector<double>* f)
{
	frequency=f;
}
void cef_clock::setSkew(unsigned s)
{
	skew=s;
}
void cef_clock::setDerivedID(unsigned d)
{
	derived_from_id=d;
}
void cef_clock::setDerivType(cef_derivation_type t)
{
	derivation_type=t;
}

void cef_clock::setDerivPhase(int p)
{
	derivation_phase=p;
}

void cef_clock::setDerived(bool d)
{
	derived=d;
}
//Getters
std::string cef_clock::getName()
{
	return name;
}
unsigned cef_clock::getID()
{
	return id;
}
vector<double>* cef_clock::getFrequency()
{
	return frequency;
}
unsigned cef_clock::getSkew()
{
	return skew;
}
unsigned cef_clock::getDerivedID()
{
	return derived_from_id;
}
cef_derivation_type cef_clock::getDerivType()
{
	return derivation_type;
}

int cef_clock::getDerivPhase()
{
	return derivation_phase;
}

bool cef_clock::isDerived()
{
	return derived;
}
#ifdef _DEBUG
void cef_clock::print()
{
	cout<<"CEF Clock\nBEGIN\n";
	cout<<"Name: "<<name<<" ID: "<<id<<" Skew: "<<skew<<" Frequency: "<<endl;
	if(frequency)
	{
		for(unsigned i=0;i<frequency->size();i++)
		{
			cout<<(*frequency)[i]<<endl;
		}
	}
	cout<<"Derived: "<<derived<<" Derived From: "<<derived_from_id<<" Derivation Type: "<<derivation_type<<" Derivation Phase: "<<derivation_phase<<endl;
	cout<<"END\n";
}
#endif
cef_powernet::cef_powernet()
{
	name="default";
	id=0;
	voltage=NULL;
	derived_from_id=0;
	derived=false;
}
cef_powernet::cef_powernet(std::string n,unsigned i, std::vector<double>* v, unsigned d, bool t)
{
	name=n;
	id=i;
	voltage=v;
	derived_from_id=d;
	derived=t;
}
cef_powernet::~cef_powernet()
{
	delete voltage;
}
//Setters
void cef_powernet::setName(std::string n)
{
	name=n;
}
void cef_powernet::setID(unsigned i)
{
	id=i;
}
void cef_powernet::setVoltage(vector<double>* v)
{
	voltage=v;
}
void cef_powernet::setDerivedID(unsigned d)
{
	derived_from_id=d;
}
void cef_powernet::setDerived(bool d)
{
	derived=d;
}
//Getters
std::string cef_powernet::getName()
{
	return name;
}
unsigned cef_powernet::getID()
{
	return id;
}
vector<double>* cef_powernet::getVoltage()
{
	return voltage;
}
unsigned cef_powernet::getDerivedID()
{
	return derived_from_id;
}
bool cef_powernet::isDerived()
{
	return derived;
}
#ifdef _DEBUG
void cef_powernet::print()
{
	cout<<"CEF Power Network\nBEGIN\n";
	cout<<"Name: "<<name<<" ID: "<<id<<" Voltage: "<<endl;
	if(voltage)
	{
		for(unsigned i=0;i<voltage->size();i++)
		{
			cout<<(*voltage)[i]<<endl;
		}
	}
	cout<<"Derived: "<<derived<<" Derived From: "<<derived_from_id<<endl;
	cout<<"END\n";
}
#endif
cef_system_properties::cef_system_properties()
{
	fp_bounding_box=NULL;
	powernets=NULL;
	clocks=NULL;
}
cef_system_properties::cef_system_properties(std::pair<double,double>* bb,std::vector<cef_clock*>* c,std::vector<cef_powernet*>* p)
{
	fp_bounding_box=bb;
	clocks=c;
	powernets=p;
}
cef_system_properties::~cef_system_properties()
{
	if(fp_bounding_box) delete fp_bounding_box;
	if(clocks)
	{
		for(unsigned i=0;i<clocks->size();i++)
		{
			delete (*clocks)[i];
		}
	 delete clocks;
	}
	if(powernets)
	{
		for(unsigned i=0;i<powernets->size();i++)
		{
			delete (*powernets)[i];
		}
	 delete powernets;
	}
}
	//Setters
void cef_system_properties::setBoundingBox(std::pair<double,double>* bb)
{
	fp_bounding_box=bb;
}
void cef_system_properties::setClocks(std::vector<cef_clock*>* c)
{
	clocks=c;	
}
void cef_system_properties::setPowerNets(std::vector<cef_powernet*>* p)
{
	powernets=p;	
}
	//Getters
std::pair<double,double>* cef_system_properties::getBoundingBox()
{
	return fp_bounding_box;
}
std::vector<cef_clock*>* cef_system_properties::getClocks()
{
	return clocks;
}
std::vector<cef_powernet*>* cef_system_properties::getPowerNets()
{
	return powernets;
}
#ifdef _DEBUG
void cef_system_properties::print()
{
	cout<<"CEF System Properties\nBEGIN\n";
	cout<<fp_bounding_box << endl;
	if(fp_bounding_box)
	{
		cout<<"Bounding Box (x,y): "<<fp_bounding_box->first<<","<<fp_bounding_box->second<<endl;
	}
	if(clocks)
	{
		for(unsigned i=0;i<clocks->size();i++)
		{
			(*clocks)[i]->print();
		}
	}
	if(powernets)
	{
		for(unsigned i=0;i<powernets->size();i++)
		{
			(*powernets)[i]->print();
		}
	}
	cout<<"END\n";
}

#endif
